/*
 * BanBu_ThemeAndBubbleViewController
 * @description 本文件提供设置中的个性化主题的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供设置中的个性化主题的ViewController
 */


#import "BanBu_ThemeAndBubbleViewController.h"
#import "BanBu_ThemeViewController.h"
#import "BanBu_ImageView.h"
#import "BanBu_NavButton.h"
#import "BanBu_ThemeManager.h"
#import "BanBu_ChatBackgroundSettingViewController.h"
#import "BanBu_BubbleViewController.h"
#import "BanBu_MainCell.h"
@interface BanBu_ThemeAndBubbleViewController ()

@end

@implementation BanBu_ThemeAndBubbleViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
    [UIView setAnimationsEnabled:YES];
    [super viewWillAppear:YES];
    [table reloadData];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = NSLocalizedString(@"interestingTheme", nil);
    
//    BanBu_NavButton *btn_return = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeBack];
//    btn_return.frame=CGRectMake(0, 0,50, 30);
//    [btn_return addTarget:self action:@selector(popself) forControlEvents:UIControlEventTouchUpInside];
////    [btn_return setTitleEdgeInsets:UIEdgeInsetsMake(3, 2, 2, 2)];
//    [btn_return setTitle:NSLocalizedString(@"returnButton", nil) forState:UIControlStateNormal];
//    btn_return.titleLabel.font = [UIFont systemFontOfSize:14];
//    UIBarButtonItem *cancelItem = [[[UIBarButtonItem alloc] initWithCustomView:btn_return] autorelease];
//    self.navigationItem.leftBarButtonItem = cancelItem;
//    [btn_return release];

    
    table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, __MainScreen_Width, __MainScreen_Height-44) style:UITableViewStyleGrouped];
    table.delegate  = self;
    table.dataSource = self;
    [self.view addSubview:table];
    
    BanBu_ImageView *img = [[[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeTable]autorelease];
    table.backgroundView = img;
    
    
    dataArr = [[NSMutableArray alloc] initWithObjects:NSLocalizedString(@"colorfulBubble", nil),NSLocalizedString(@"chatBackgroundImage", nil), NSLocalizedString(@"changeTheme", nil),nil];
    
    
	// Do any additional setup after loading the view.
}
-(void)dealloc
{
    [dataArr release],dataArr = nil;
    [super dealloc];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifier = @"themeAndBubbleCellIndentifier";
    BanBu_MainCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    
    if(!cell)
    {
        cell = [[[BanBu_MainCell alloc] initWithStyle:UITableViewCellStyleValue1    reuseIdentifier:cellIndentifier]autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }
    
    if([ThemeManager getThemeImage:@"tablecell_backimage.png"])
        cell.backgroundColor = [UIColor colorWithPatternImage:[ThemeManager getThemeImage:@"tablecell_backimage.png"]];
    else
        cell.backgroundColor = nil;
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = [dataArr objectAtIndex:indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    [self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        BanBu_BubbleViewController * bubbleViewController = [[BanBu_BubbleViewController alloc]init];
        
        [self.navigationController pushViewController:bubbleViewController animated:YES];
        [bubbleViewController release];
    }
    if(indexPath.row == 1)
    {
        BanBu_ChatBackgroundSettingViewController * chatBGSetting = [[BanBu_ChatBackgroundSettingViewController alloc]init];
        [self.navigationController pushViewController:chatBGSetting animated:YES];
        [chatBGSetting release];
    }
    if(indexPath.row == 2)
    {
        BanBu_ThemeViewController *theme = [[BanBu_ThemeViewController alloc] init];
        [self.navigationController pushViewController:theme animated:YES];
        [theme release];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
